package com.bawei.composeui2207a.day03

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.VerticalPager
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.filled.ThumbUp
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.bawei.composeui2207a.R
import java.text.SimpleDateFormat

/**
 * 作者：赵亮
 * 时间：2024/12/12 11:04
 * 功能：列表 网格
 */

data class InfoEntity(val img: Int, val name: String, val time: String)

@Composable
fun Day03_1() {
    // 1. 准备数据
    val list = mutableListOf<InfoEntity>()
    repeat(30) {
        list.add(
            InfoEntity(
                R.drawable.zhubajie,
                "猪八戒.png",
                "${SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(System.currentTimeMillis())}"
            )
        )
    }

    Column {
        // 横向列表
        LazyVerticalGrid(columns = GridCells.Fixed(2)) {
            items(list) {

                // 是否点赞
                var isZan by remember {
                    mutableStateOf(false)
                }

                // 显示对话框
                var isShow by remember {
                    mutableStateOf(false)
                }

                Box(modifier = Modifier.clickable {
                    // 条目点击
                    isShow = true
                }) {
                    Row {
                        // 图片
                        Image(
                            modifier = Modifier
                                .size(100.dp)
                                .clip(RoundedCornerShape(15.dp)),
                            contentScale = ContentScale.Crop,
                            painter = painterResource(id = it.img),
                            contentDescription = null
                        )
                        // 两个文字
                        Column {
                            Text(text = it.name)
                            Text(text = it.time)
                            Row {
                                Icon(
                                    modifier = Modifier.clickable {
                                        isZan = !isZan
                                    },
                                    tint = if (isZan) Color.Red else Color.Gray,
                                    imageVector = Icons.Default.ThumbUp,
                                    contentDescription = null
                                )
                                Icon(
                                    imageVector = Icons.Default.Favorite,
                                    contentDescription = null
                                )
                                Icon(imageVector = Icons.Default.Star, contentDescription = null)
                            }
                        }
                    }
                    Box(
                        modifier = Modifier
                            .background(color = Color.Yellow)
                    ) {
                        Text(text = "直播中")
                    }
                }

                if (isShow) {
                    AlertDialog(
                        dismissButton = { Text(text = "取消") },
                        title = { Text(text = "提示！") },
                        text = { Text(text = "是否删除！") },
                        onDismissRequest = { isShow = false },
                        confirmButton = { Text(text = "确定") })

                }
            }
        }
        // 竖向列表

    }
}

@Preview(showSystemUi = true)
@Composable
fun Day03_1Preview() {
    Day03_1()
}

